import requests
from requests.auth import HTTPBasicAuth
from config import osconfig
class OpenSearchAdapter:
    def __init__(self, idx_name):
        self.url = osconfig.url
        self.port = osconfig.port
        self.idx_name = idx_name
        self.basic_auth = HTTPBasicAuth(osconfig.username, osconfig.password)
        self.base_url = f"https://{self.url}:{self.port}/{self.idx_name}"
        self.headers = {
            "Content-Type": "application/json"
        }
class SpreadSheetClient(OpenSearchAdapter):
    def __init__(self):
        self.idx_name = osconfig.idx_name
        super(SpreadSheetClient, self).__init__(self.idx_name)
    def search(self, query_condition, filter=None):
        query_map = {
            "_source": True,
            "query": query_condition
        }
        print(query_map)
        import pdb;pdb.set_trace()
        req = requests.request("GET", url=f"{self.base_url}/_search?pretty=true", auth=self.basic_auth, headers=self.headers, json=query_map)
        if req.status_code != 200:
            print(req.status_code)
            import pdb;pdb.set_trace()
        return json.loads(req.content)

ssc = SpreadSheetClient()